import Axios from "axios"
import { getUser } from '@/libs/util'
import { message } from 'ant-design-vue'

const option = {
    baseURL: process.env.VUE_APP_BASEURL,
    timeout: 5000,

}
const instance = Axios.create(option)
instance.interceptors.request.use(config => {
    if (!config.url.includes('/login')) {

        const user = getUser()
        if (user && user.token) {
            config.headers.Authorization = 'Bearer ' + user.token
        }
    }
    return config
})
instance.interceptors.response.use(res => {
    if (res.data.resultCode === '-1') {
        message.error(res.data.resultMsg || '系统异常')

    }
    return res
},
    error => {
        console.log('interceptors.response / error:', error)
        return Promise.reject(error);
    }
)
// export default {
//     request(options) {
//         return instance(options)
//     }
// }
export default instance